<template>
  <div class="container">
    <nav-bar :title="title" />
    <!-- <div class="top">
      <div v-for="(item,index) in topData" :key="'fans'+index" class="all">
        <div class="num">
          {{ item.num }}
        </div>
        <div>{{ item.title }}</div>
      </div>
    </div> -->

    <div v-if="lsitData.length>0" class="content">
      <div class="tit">订单列表</div>
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div class="list">
          <div v-for="(item,index) in lsitData" :key="'zhi'+index" class="li">
            <div class="top">
              <span v-if="type==1" class="types">{{ '采购补贴' }}</span>
              <span v-else-if="type==3" class="types">{{ '推荐奖励' }}</span>
              <span v-else class="types">积分赠送</span>
              <span>【{{ item.id }}】</span>
            </div>
            <div class="contents">
              <div class="left">
                <img class="userAvator" :src="item.payImgUrl" alt="">
                <!-- <div class="tags" style="margin-left: 10px;">
                  <div class="buy" style="display: flex;align-items: center;">
                    <div class="title" style="color: #4A73FD;">买方：</div>
                    <div class="info">{{ item.buyUserName }}</div>
                  </div>
                  <div class="sale" style="display: flex;align-items: center;margin-top: 5px">
                    <div class="title" style="color: #4A73FD;">卖方：</div>
                    <div class="info">{{ item.saleUserName }}</div>
                  </div>
                </div> -->
              </div>
              
              <div class="right">
                +{{ type == 1? item.incomeListingCash: type == 2? item.incomeListingPoints : item.recommendRewardCash }}
              </div>
            </div>
            <div class="time">{{ item.orderTime }}</div>
          </div>
        </div>
      </van-list>
    </div>
    <van-empty v-else description="暂无数据" />

  </div>
</template>
<script>
import { getCashIncomeList, getPointsIncomeList, getRecommendedRewardsList } from '@/api/fans'
import { mapGetters } from 'vuex'
export default {
  name: 'FansNum',
  computed: {
    ...mapGetters(['userInfo'])
  },
  data() {
    return {
      title: '',
      type: 0,
      topData: [
        {
          title: '日收益',
          num: '100.00'
        },
        {
          title: '周收益',
          num: '100.00'
        },
        {
          title: '月收益',
          num: '100.00'
        },
        {
          title: '总收益',
          num: '100.00'
        }
      ],
      lsitData: [
      ],
      loading: true,
      finished: false,
      page: 1
    }
  },
  async created() {
    console.log(this.$route)
    const type = this.$route.query.type
    if (type == 1) {
      this.title = '采购补贴'
    } else if (type == 2) {
      this.title = '积分赠送'
    } else {
      this.title = '推荐收益'
    }
    this.type = type
    await this.init()
  },
  methods: {
    async init() {
      let res = null
      if (this.type == 1) {
        res = await getCashIncomeList({ pageNum: this.page })
      } else if (this.type == 2) {
        res = await getPointsIncomeList({ pageNum: this.page })
      } else {
        res = await getRecommendedRewardsList({ pageNum: this.page })
      }
      console.log(res)
      const records = res.map.page?.records || []
      records.forEach(item => {
        console.log(item.orderTime)
        const times = new Date(item.orderTime).toLocaleString({ hour12: false }, 'yyyy-MM-dd hh:mm:ss')
        console.log('times==', times)
        item.orderTime = times
      })
      if (this.page == 1) {
        this.lsitData = records
      } else {
        records.forEach(item => {
          this.$set(this.lsitData, this.lsitData.length, item)
        })
      }
      if (records.length !== 10) {
        this.finished = true
      }

      this.loading = false
    },
    onLoad() {
      this.page++
      this.init()
    }
  }
}
</script>
  <style lang='scss' scoped>
    .container{
      box-sizing: border-box;
      background-color: #f6f6f6;
      // padding: 24px;
      .top{
        box-sizing: border-box;
        margin: 0 24px;
        padding: 40px 24px;
        margin-top: 20px;
        background-color: #4A73FD;
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #fff;
        font-size: 24px;
        border-radius: 20px;

        .all{
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;

          .num{
            margin-bottom: 20px;
          }
        }
      }

      .content{
        margin: 0 24px;
        margin-top: 30px;
        padding-bottom: 20px;
        .tit{
          font-size: 30px;
          font-weight: 600;
        }
        .list{

          .li{
            display: flex;
            flex-direction: column;
            // justify-content: space-around;
            background-color: #fff;
            padding: 24px;
            margin-top: 24px;
            border-radius: 10px;
            .top{
                width: 100%;
                background-color: unset;
                justify-content: left;
                color: #000;
                padding: 0;
                margin: 0;
                font-size: 30px;

                .types{
                    color: #4A73FD;
                    margin-right: 10px
                }
            }
            .contents{
                margin-top: 20px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                // justify-content: center;

                .left{
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    .userAvator{
                        width: 120px;
                        height: 120px;
                        border-radius: 5px;
                        margin-bottom: 5px
                    }
                    .truename{
                        width: 300px;
                        margin-left: 20px;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }
                }
                .right{
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    font-size: 30px;
                    color: #ef3929;
                }

            }
            .time{
                margin-top: 20px;
            }
          }
        }
      }
    }

  </style>
